package jy.game.tools;

import android.text.TextUtils;

import java.util.Random;

public class Tools {
    private static Random random = new Random();

    public static <T> T loadObjectFromXML(String xmlPath) {
        return null;
    }

    public static String concat(String[] array) {
        return TextUtils.join("", array);
    }

    public static String trimEnd(String value, char ch) {

        // Use replaceFirst to remove trailing spaces.
        String regex = String.format("(%c)+$", ch);
        return value.replaceFirst(regex, "");
    }

    public static String trimStart(String value, char ch) {
        // Remove leading spaces.
        String regex = String.format("^(%c)+", ch);
        return value.replaceFirst(regex, "");
    }

    public static String trim(String value, char ch) {
        return trimEnd(trimStart(value, ch), ch);
    }

    public static double getRandom(double a, double b) {
        double num = Tools.random.nextDouble();
        // 交换a,b
        if (b > a) {
            double num2 = a;
            a = b;
            b = num2;
        }
        // 1, 100
        return b + (a - b) * num;
    }

    // Token: 0x06000269 RID: 617 RVA: 0x0000379F File Offset: 0x0000199F
    public static int getRandomInt(int a, int b) {
        return (int) Tools.getRandom(a, b + 1);
    }

    public static boolean probabilityTest(double p) {
        return p >= 0.0 && (p >= 1.0 || Tools.random.nextDouble() < p);
    }

}
